import Vue from "vue";

import userApi from '@/api/userApi.js'
/* 用户信息 */
export default {
	namespaced: true,
	state: {
		identity: 1, // 1 普通用户  2 发电人员
		userInfo: null,
		userId: null,
		token: null,
		webSocket: null,
		messageTouser: null,
		message: null
	},
	mutations: {
		setUserInfo(state, payLoad) {
			state.userInfo = payLoad
		},
		setUserToken(state, payLoad) {
			state.token = payLoad
		},
		setUserId(state, id) {
			state.userId = id
		},
		setIdentity(state, id) {
			state.identity = id
		},
		removeState(state) {
			state.identity = 1
			state.userInfo = null
			state.userId = null
			state.token = null
			state.webSocket = null
			state.messageTouser = null
			state.message = null
		},
		setWebSocket(state, payLoad) {
			console.log(payLoad);
			state.webSocket = payLoad
		},
		getMessageTouser(state, payLoad) {
			console.log(payLoad, 'aaaaaaaaaaaaaa')
			state.messageTouser = payLoad
		},
		getMessage(state, payLoad) {
			state.message = payLoad
		}
	},
	actions: {
		remove({
			commit
		}, payLoad) {
			commit('removeState','')
		},
		getUserInfo({
			commit
		}, payLoad) {
			// commit('setUserToken', payLoad)
			return new Promise((resolve, reject) => {
				userApi.getUserInfo().then(res => {
					commit('setUserInfo', res.data)
					commit('setUserId', res.data.id)
					resolve(res.data)
				})
			})
		}
	},
};